import unittest, requests


class Keji(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')

    def tearDown(self) -> None:
        print('end case')

    host = 'https://10.59.9.18/'

    # 登录
    userId = None
    sessionId = None

    def test_keji_01(self):
        login = requests.post(url=Keji.host + 'techApi/user/v1/login', verify=False,
                              data={'phone': '15535738378',
                                    'pwd': 'S0hBZElnMkExQml6T21vYVRacVNmN2lSRHUxNGVsK2JMSXlBUkpWSmJsM0JJYkN0M0RYaTZLMDh0N3pLSU1FYzgvR1FFZzhZMExYaXFqNWE1WlBiUGd4bWdYWFVvZ09VTzdYcmpZOUZRRStqUkhqN1RVc25GSDJvaWp1STI3Tm1WdWpDdlRZTUpGVit5WGRMOTZlZlY3eTlKWVJENzlIdzlPN2xNMWQ5eUEwPQ'})
        print(login.json())
        Keji.userId = login.json()['result']['userId']
        Keji.sessionId = login.json()['result']['sessionId']

    # 查询所有会员商品
    commodityId = None

    def test_keji_02(self):
        CommodityList = requests.get(url=Keji.host + 'techApi/tool/v1/findVipCommodityList', verify=False)
        print(CommodityList.json())
        Keji.commodityId = CommodityList.json()['result'][0]['commodityId']
        print('commodityId:', Keji.commodityId)

    # 社区列表
    signature = None

    def test_keji_03(self):
        CommunityList = requests.get(url=Keji.host + 'techApi/community/v1/findCommunityList', verify=False,
                                     headers={'userId': str(Keji.userId), 'sessionId': str(Keji.sessionId)},
                                     params={'page': 1, 'count': 5})
        print(CommunityList.json())
        Keji.signature = CommunityList.json()['result'][0]['signature']
        print(Keji.signature)

    # 用户购买VIP
    def test_keji_04(self):
        createGroup = requests.post(url=Keji.host + 'techApi/tool/verify/v1/buyVip', verify=False,
                                   headers={'userId': str(Keji.userId), 'sessionId': str(Keji.sessionId)},
                                   data={'commodityId': str(Keji.commodityId), 'sign': str(Keji.signature)})
        print(createGroup.json())

    # 支付
    def test_keji_05(self):
        createGroup = requests.post(url=Keji.host + 'techApi/tool/verify/v1/pay', verify=False,
                                    headers={'userId': str(Keji.userId), 'sessionId': str(Keji.sessionId)},
                                    params={'orderId': '20180906075947989', 'payType': '1'})
        print(createGroup.json())


if __name__ == '__main__':
    unittest.main()
